﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace LinearAlgebra
{
    public partial class MatrixBasisChangeDialog : Form
    {
        float b11_2, b12_2, b21_2, b22_2;
        public MatrixBasisChangeDialog(float b11_1, float b21_1, float b12_1, float b22_1,
                                       float b11_2, float b21_2, float b12_2, float b22_2)
        {
            InitializeComponent();

            this.b11_2 = b11_2;
            this.b12_2 = b12_2;

            this.b21_2 = b21_2;
            this.b22_2 = b22_2;

            float determinate = b11_2 * b22_2 - b12_2 * b21_2;

            float inverseB11 = b22_2 / determinate;
            float inverseB21 = -b21_2 / determinate;

            float inverseB12 = -b12_2 / determinate;
            float inverseB22 = b11_2 / determinate;

            float result11 = inverseB11 * b11_1 + inverseB12 * b21_1;
            float result12 = inverseB11 * b12_1 + inverseB12 * b22_1;

            float result21 = inverseB21 * b11_1 + inverseB22 * b21_1;
            float result22 = inverseB21 * b12_1 + inverseB22 * b22_1;

            OrigBasis11_1.Text = b11_1.ToString("0.00", CultureInfo.InvariantCulture);
            OrigBasis12_1.Text = b12_1.ToString("0.00", CultureInfo.InvariantCulture);
            OrigBasis21_1.Text = b21_1.ToString("0.00", CultureInfo.InvariantCulture);
            OrigBasis22_1.Text = b22_1.ToString("0.00", CultureInfo.InvariantCulture);

            OrigBasis11_2.Text = b11_1.ToString("0.00", CultureInfo.InvariantCulture);
            OrigBasis12_2.Text = b12_1.ToString("0.00", CultureInfo.InvariantCulture);
            OrigBasis21_2.Text = b21_1.ToString("0.00", CultureInfo.InvariantCulture);
            OrigBasis22_2.Text = b22_1.ToString("0.00", CultureInfo.InvariantCulture);

            NewBasis11_1.Text = b11_2.ToString("0.00", CultureInfo.InvariantCulture);
            NewBasis12_1.Text = b12_2.ToString("0.00", CultureInfo.InvariantCulture);
            NewBasis21_1.Text = b21_2.ToString("0.00", CultureInfo.InvariantCulture);
            NewBasis22_1.Text = b22_2.ToString("0.00", CultureInfo.InvariantCulture);

            NewBasis11_2.Text = b11_2.ToString("0.00", CultureInfo.InvariantCulture);
            NewBasis12_2.Text = b12_2.ToString("0.00", CultureInfo.InvariantCulture);
            NewBasis21_2.Text = b21_2.ToString("0.00", CultureInfo.InvariantCulture);
            NewBasis22_2.Text = b22_2.ToString("0.00", CultureInfo.InvariantCulture);

            Inv11_1.Text = inverseB11.ToString("0.00", CultureInfo.InvariantCulture);
            Inv12_1.Text = inverseB12.ToString("0.00", CultureInfo.InvariantCulture);
            Inv21_1.Text = inverseB21.ToString("0.00", CultureInfo.InvariantCulture);
            Inv22_1.Text = inverseB22.ToString("0.00", CultureInfo.InvariantCulture);

            Inv11_2.Text = inverseB11.ToString("0.00", CultureInfo.InvariantCulture);
            Inv12_2.Text = inverseB12.ToString("0.00", CultureInfo.InvariantCulture);
            Inv21_2.Text = inverseB21.ToString("0.00", CultureInfo.InvariantCulture);
            Inv22_2.Text = inverseB22.ToString("0.00", CultureInfo.InvariantCulture);
            
            Result11.Text = result11.ToString("0.00", CultureInfo.InvariantCulture);
            Result12.Text = result12.ToString("0.00", CultureInfo.InvariantCulture);
            Result21.Text = result21.ToString("0.00", CultureInfo.InvariantCulture);
            Result22.Text = result22.ToString("0.00", CultureInfo.InvariantCulture);
        }

        private void MoreDetail_Click(object sender, EventArgs e)
        {
            InverseExplain2DDialog form = new InverseExplain2DDialog(b11_2, b21_2, b12_2, b22_2);
            form.Show( );
        }

        private void Ok_Click(object sender, EventArgs e)
        {
            Close( );
        }
    }
}
